package key.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * User: key
 * ClassName:StrUtils
 * Date: 2023/5/8
 * Time: 21:02
 * description:
 */
public class StrUtils {
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    public static boolean isNotEmpty(String data){
        return data != null && !data.trim().equals("") && data.length() > 0;
    }
    public static Integer strToInteger(String data){
        boolean b = isNotEmpty(data);
        if(b){
            return Integer.valueOf(data);
        }
        return -1;
    }
    public static Double strToDouble(String data){
        boolean b = isNotEmpty(data);
        if(b){
            return Double.valueOf(data);
        }
        return -1.0;
    }
    public static Date strToDate(String data){
        boolean b = isNotEmpty(data);
        try {
            if(b){
                return sdf.parse(data);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static boolean isNotEmpty(String... data){
        boolean b = true;
        for (String datum : data) {
            b = (datum != null && datum.length() > 0);
            if(!b){
                break;
            }
        }
        return b;
    }
}
